<!--
* @Author: white_queen
* @Date: 2024-07-16 15:00:16
* @LastEditors: white_queen
* @LastEditTime: 2024-07-17 14:44:17
* @FilePath: /pages/mall/index/index.vue
* @Description: 商城模块
-->
<template>
	<view class="page">
		<!-- 自定义导航栏 -->
		<u-navbar leftIcon="search" title="妙缘能量珠宝" bgColor="rgba(255,255,255,0)" @leftClick="search"></u-navbar>
		<!-- 轮播 -->
		<u-swiper :list="bannerList" @change="(e) => (current = e.current)" :autoplay="true" height="600" radius="0">
			<view slot="indicator" class="indicator">
				<view class="indicator__dot" v-for="(item, index) in list5" :key="index" :class="[index === current && 'indicator__dot--active']"></view>
			</view>
		</u-swiper>

		<view class="type-list">
			<image v-for="(item, index) in list.class" :key="item.id" :src="item.image" mode="widthFix" @click="pageTo(index)"></image>
		</view>

		<image class="t1" src="../../../static/images/t1.png" mode="widthFix"></image>
		<video class="video" :src="list.brand_video" controls></video>
		<image class="t1" src="../../../static/images/t2.png" mode="widthFix"></image>
		<video class="video" src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4" controls></video>

		<!-- 轮播 -->
		<view class="swiper-view">
			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
				<swiper-item class="swiper-item" v-for="item in list.goods" :key="item.id">
					<view class="title">探索更多</view>
					<view class="title-line"></view>
					<!-- 商品图占位 -->
					<image class="shop-img-item" :src="item.show_images" mode=""></image>
					<view class="shop-name">{{ item.name }}</view>
					<view class="price-view">￥{{ formatNumberToThousands(item.info.price_founder) }}起售</view>
					<view class="buy-button" @click="buy(item)">购买</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="vip-image">
			<image class="t1" src="../../../static/images/vip.png" mode="widthFix"></image>
			<view class="button-vip"></view>
		</view>
	</view>
</template>

<script>
import httpApi from '../../../http';
import { formatNumberToThousands } from '@/utils/index.js';
export default {
	onLoad() {
		this.init();
	},
	data() {
		return {
			current: 0,
			bannerList: ['https://picsum.photos/750/1500?id=1', 'https://picsum.photos/750/1500?id=12', 'https://picsum.photos/750/1500?id=3'],
			priceNum: 23600,
			list: []
		};
	},
	methods: {
		init() {
			httpApi.MallApi.getClassType({}).then((res) => {
				console.log(res.data);
				// res.data.brand_video = this.$url + res.data.brand_video;
				// res.data.jewelry_video = this.$url + res.data.jewelry_video;
				let arr = [];
				for (let item of res.data.banner) {
					arr.push(item.image);
				}
				this.bannerList = arr;
				this.list = res.data;
			});
		},
		// 注册方法
		formatNumberToThousands,
		search() {
			console.log('点击了导航栏的搜索');
		},
		pageTo(type) {
			uni.navigateTo({
				url: '/pages/mall/threeSelect/threeSelect?type=' + type,
				success: (res) => {},
				fail: () => {},
				complete: () => {}
			});
		},
		buy(item) {
			uni.navigateTo({
				url: '/pages/mall/productDetails/productDetails?id=' + item.id,
				success: (res) => {},
				fail: () => {},
				complete: () => {}
			});
		}
	}
};
</script>
<style lang="scss" scoped>
.indicator {
	@include flex(row);
	justify-content: center;
	// position: fixed;
	// bottom: 10rpx;
	&__dot {
		height: 16rpx;
		width: 16rpx;
		border-radius: 100px;
		background-color: rgba(255, 255, 255, 0.35);
		margin: 0 5px;
		transition: background-color 0.3s;

		&--active {
			width: 32rpx;
			background-color: $uni-theme-color;
		}
	}
}
</style>
<style lang="scss" scoped>
image {
	display: block;
}
.page {
	background: $uni-page-bg;
	.type-list {
		width: 750rpx;
		margin-top: 42rpx;
		image {
			width: 100%;
			display: block;
		}
	}

	.t1 {
		width: 100%;
	}
	.video {
		width: 750rpx;
		height: 600rpx;
	}
	.swiper-view {
		padding: 50rpx;
		box-sizing: border-box;
		.swiper {
			width: 100%;
			height: 920rpx;
		}
		.swiper-item {
			width: 100%;
			background-color: #fff;
			padding-top: 50rpx;
			.title {
				font-family: SourceHanSerifCN, SourceHanSerifCN;
				font-weight: 500;
				font-size: 24rpx;
				color: #333333;
				line-height: 34rpx;
				text-align: center;
				font-style: normal;
			}
			.title-line {
				width: 190rpx;
				height: 2rpx;
				background: #333333;
				margin: 20rpx auto 0;
			}
			.shop-img-item {
				margin: 78rpx auto 0;
				width: 278rpx;
				height: 416rpx;
			}
			.shop-name {
				font-family: SourceHanSerifCN, SourceHanSerifCN;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;
				line-height: 40rpx;
				text-align: center;
				font-style: normal;
				margin-top: 86rpx;
			}
			.price-view {
				margin-top: 10rpx;
				font-family: SourceHanSerifCN, SourceHanSerifCN;
				font-weight: 500;
				font-size: 24rpx;
				color: #333333;
				line-height: 34rpx;
				text-align: center;
				font-style: normal;
			}
			.buy-button {
				margin: 30rpx auto 0;
				width: 208rpx;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
				background: #000000;
				font-family: SourceHanSerifCN, SourceHanSerifCN;
				font-weight: 500;
				font-size: 24rpx;
				color: #ffffff;
				font-style: normal;
			}
		}
	}
	.vip-image {
		width: 750rpx;
		position: relative;
		.button-vip {
			width: 200rpx;
			height: 60rpx;
			// border: 1px solid #000;
			position: absolute;
			left: 50%;
			transform: translate(-50%);
			bottom: 50rpx;
		}
	}
}
</style>
